package com.hnevc.mytrafficdemo.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import com.hnevc.mytrafficdemo.R;
import com.hnevc.mytrafficdemo.adapter.CarListAdapter;
import com.hnevc.mytrafficdemo.entity.Car;
import com.hnevc.mytrafficdemo.util.dialog.RechargeDialog;

import java.util.ArrayList;
import java.util.List;

public class AcountManageActivity extends AppCompatActivity {
    List<Car> mCarList;
    CarListAdapter mCarListAdapter ;
    ListView mListView ;
    TextView mTvMultiCharge;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_acount_manage);
        initData();
        initView();
    }

    private void initView() {
        mTvMultiCharge = (TextView) findViewById(R.id.header_extra_multicharge);
        mListView = (ListView) findViewById(R.id.id_lv_accounts);
        mCarListAdapter = new CarListAdapter(this,mCarList);
        mListView.setAdapter(mCarListAdapter);

        mTvMultiCharge.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                RechargeDialog rechargeDialog = new RechargeDialog(AcountManageActivity.this,
                        "车辆账户充值",mCarList);
                rechargeDialog.show();
            }
        });
    }

    private void initData() {
        int []  ids = new int[]{1,2,3,4};
        int[] carDrawables = new int[]{R.drawable.bengci,R.drawable.baoma
                ,R.drawable.zhonghua,R.drawable.mazida};
        String[] carOwnners = new String[] {"张三","李四","王五","赵六"};
        String[] carNumbers = new String[]{"辽A10001","辽A10002","辽A10003","辽A10004"};
        int[] carBalances= new int[]{100,99,103,1};

        mCarList = new ArrayList<>();
        for(int i=0;i<ids.length;i++) {
            Car car = new Car();
            car.setCarId(ids[i]);
            car.setCardDrawableResource(carDrawables[i]);
            car.setCardNum(carNumbers[i]);
            car.setCarOwnner(carOwnners[i]);
            car.setCarBalance(carBalances[i]);
            mCarList.add(car);
        }
    }
}
